﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class IndustryGateway
    {
        public ObservableCollection<Industry> GetAllindustries()
        {
            ObservableCollection<Industry> allIndustry = new ObservableCollection<Industry>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchIndustryList());
            if (dt.Rows.Count <= 0)
            {
                return allIndustry;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allIndustry.Add(new Industry()
                {
                    IndustryId = Convert.ToInt32(dataRow["Industry_ID"].ToString()),
                    IndustryName = dataRow["Industry_Name"].ToString(),
                });
            }
            return allIndustry;
        }


        public void SaveNewIndustryToDatabase(string industry)
        {
            string query = QueryProvider.MakeSQLQueryToInsertIdustryToDatabase(industry);
            DBHelper.ExecuteSqlQuery(query);
        }

        public void EditIndustryToDatabase(string industry, int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToEditIndustryToDatabase(industry, rowid);
            DBHelper.ExecuteSqlQuery(query);

        }

        public void DeleteindustryFromDatabase(int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToDeleteIndustryFromDatabase(rowid);
            DBHelper.ExecuteSqlQuery(query);
        }
    }
}
